package com.qzing.springbootmybatisdemo05.controller;


import com.qzing.springbootmybatisdemo05.mapper.UserMapper;
import com.qzing.springbootmybatisdemo05.pojo.User;
import com.qzing.springbootmybatisdemo05.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/// Controller -> Service -> Mapper -> Mysql
@RestController
@RequestMapping("/user")
public class UserServiceController {

    @Autowired
    UserService userService;

    @GetMapping("/users")
    public List<User> queryUserList(){
        return userService.queryUserList();
    }

    @GetMapping("/get/{id}")
    public User queryUserById(@PathVariable("id") Integer id){
        return userService.queryUserById(id);
    }

    @GetMapping("/add")
    public int addUser(){
        User user = new User(199, "tom", "123456");
        return userService.addUser(user);
    }

    @GetMapping("/update")
    public int updateUser(){
        User user = new User(199, "tom", "9876542");
        return userService.updateUser(user);
    }

    @GetMapping("/delete/{id}")
    public int deleteUser(@PathVariable("id") Integer id){
        return userService.deleteUser(id);
    }




}
